/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.List;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author ipti
 */
@Entity
public class QuestResult extends AbstractEntity{
    
    @ManyToOne
    @JoinColumn(name = "person_id")
    private Person person;
    
    @ManyToOne
    @JoinColumn(name = "ask_id")
    private Asks ask;
    
    @ManyToMany(mappedBy = "questResultList")
    private List<Alias> aliasList;
    
    @Temporal(TemporalType.DATE)
    private Calendar data;
    
    @Column(name = "value")
    private String value;
    
    public QuestResult(){
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = ""
                    + ((this.getPerson() != null) ? this.getPerson().getId() : null)
                    + this.getAsk()
                    + this.getData();
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public QuestResult(Person person, Asks ask, String value) {
        this.person = person;
        this.ask = ask;
        this.value = value;
    }

    public Asks getAsk() {
        return ask;
    }

    public void setAsk(Asks ask) {
        this.ask = ask;
    }

    public Calendar getData() {
        return data;
    }

    public void setData(Calendar data) {
        this.data = data;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public List<Alias> getAliasList() {
        return aliasList;
    }

    public void setAliasList(List<Alias> aliasList) {
        this.aliasList = aliasList;
    }
}
